

// ----------src/base/base.js----------

// 获取String中name=xxx的值
String.prototype.getQueryString = function (name) {
    var reg = new RegExp("(^|&|\\?)" + name + "=([^&]*)(&|$)"), r;
    if (r = this.match(reg))
        return unescape(r[2]);
    return null;
}
// 替换字符串中{0}{1}...
String.prototype.format = function (args) {
    if (arguments.length == 0)
        return null;

    var str = this;
    for (var i = 0; i < arguments.length; i++) {
        var re = new RegExp('\\{' + (i) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}
String.prototype.endWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substring(this.length - str.length) == str)
        return true;
    else
        return false;
    return true;
}
String.prototype.startWith = function (str) {
    if (str == null || str == "" || this.length == 0 || str.length > this.length)
        return false;
    if (this.substr(0, str.length) == str)
        return true;
    else
        return false;
    return true;
}
String.prototype.isEmpty = function () {
    return this.trim() === '';
}
String.prototype.toDate = function () {
    var temp = this.toString();
    temp = temp.replace(/-/g, "/");
    var date = new Date(Date.parse(temp));
    return date;
}
Date.prototype.toFomatorString = function (formator) {
    var returnText = formator.toUpperCase();
    if (returnText.indexOf("YYYY") > -1) {
        returnText = returnText.replace("YYYY", this.getFullYear());
    }
    if (returnText.indexOf("MM") > -1) {
        returnText = returnText.replace("MM", this.getMonth() + 1);
    }
    if (returnText.indexOf("DD") > -1) {
        returnText = returnText.replace("DD", this.getDate());
    }
    if (returnText.indexOf("HH") > -1) {
        returnText = returnText.replace("HH", this.getHours());
    }
    if (returnText.indexOf("MI") > -1) {
        returnText = returnText.replace("MI", this.getMinutes());
    }
    if (returnText.indexOf("SS") > -1) {
        returnText = returnText.replace("SS", this.getSeconds());
    }
    if (returnText.indexOf("SI") > -1) {
        returnText = returnText.replace("SI", this.getMilliseconds());
    }
    return returnText;
}
// 继承实现
var __extends = this.__extends ||
    function (d, b) {
        function __() {
            this.constructor = d;
        }

        __.prototype = b.prototype;
        d.prototype = new __();
    }

// 计算字符串的字节数
var sizeof = function (str, charset) {
    var total = 0, charCode, i, len;
    charset = charset ? charset.toLowerCase() : '';
    if (charset === 'utf-16' || charset === 'utf16') {
        for (i = 0, len = str.length; i < len; i++) {
            charCode = str.charCodeAt(i);
            if (charCode <= 0xffff) {
                total += 2;
            } else {
                total += 4;
            }
        }
    } else {
        for (i = 0, len = str.length; i < len; i++) {
            charCode = str.charCodeAt(i);
            if (charCode <= 0x007f) {
                total += 1;
            } else if (charCode <= 0x07ff) {
                total += 2;
            } else if (charCode <= 0xffff) {
                total += 3;
            } else {
                total += 4;
            }
        }
    }
    return total;
}

// ----------src/base/storage.js----------

﻿var _APP_NAME = "Sale_Assist_";

/// Cookie ///

function addCookie(objName, objValue) {
    var str = objName + "=" + escape(objValue);
    document.cookie = str;
    //log("addCookie-->objName: " + objName);
}

function getCookie(objName) {
    var arrStr = document.cookie.split(";");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        if (temp[0] == objName)
            return unescape(temp[1]);
    }
}

function clearCookie() {
    var arrStr = document.cookie.split(";");
    for (var i = 0; i < arrStr.length; i++) {
        var temp = arrStr[i].split("=");
        addCookie(temp[0], '');
    }
}

/// Storage ///

function setstorage(objName, objValue) {
    objName = _APP_NAME + objName;
    var storage = window.localStorage;
    if (window.localStorage) {
        localStorage.setItem(objName, objValue);
    }
    else {
        //log('setstorage-->This browser does NOT support localStorage');
        addCookie(objName, objValue);
    }
}

function getstorage(objName) {
    objName = _APP_NAME + objName;
    var storage = window.localStorage;
    var result = '';
    if (window.localStorage) {
        for (var i = 0; i < storage.length; i++) {
            if (storage.key(i) == objName)
                result = storage.getItem(storage.key(i));
        }
    }
    else {
        //log('getstorage-->This browser does NOT support localStorage');
        getCookie(objName);
    }
    return result;
}

function clearstorage() {
    var storage = window.localStorage;
    //log('clearstorage-->clear all localStorage data ~ ~ ~');
    if (window.localStorage) {
        localStorage.clear();
    }
    else {
        //log('clearstorage-->This browser does NOT support localStorage');
        clearCookie();
    }
}



// ----------src/App.js----------

var App = App || {};

App.VERSION = '1.0';

App.Biz || (App.Biz = {});
App.Service || (App.Service = {});
App.Data || (App.Data = {});
App.Model || (App.Model = {});

App.namespace = function(ns_string) {
    var parts = ns_string.split('.');
    var parent = APP;
    var i;
    if (parts[0] === 'APP') {
        parts = parts.slice(1);
    }
    for (i = 0; i < parts.length; i += 1) {
        var p = parts[i];
        if (typeof parent[p] === 'undefined') {
            parent[p] = {};
        }
        parent = parent[p];
    }
    return parent;
};

// ----------src/Event.js----------

/**
 * 视图事件、手势的定义
 * 
 */

App.Event = (function($, App, undefined) {

    /**
     * 在不同的article间切换
     * @param {type} art
     * @param {type} step 往前或往后
     */
    var tabArticle = function(art, step) {
        var id = art.id;
        var parent = art.parentNode;
        if (parent.nodeName === 'SECTION') {
            var section_id = parent.id;
            var childs = parent.children;
            var prevArt = null;
            var idx = 0;
            var isNext = false;
            for (key in childs) {
                var child = childs[key];
                if (child.nodeName === 'ARTICLE') {
                    if (isNext) {
                        App.Router.gotoArticle(section_id, child.id);
                        return;
                    } else if (child.id === id) {
                        if (step === -1 && prevArt) {
                            App.Router.gotoArticle(section_id, prevArt.id);
                            return;
                        } else if (step === 1) {
                            isNext = true;
                        }
                    }
                    prevArt = child;
                }
            }
        }
    };

    return {
        tabArticle: tabArticle,
    };

})(Lungo.dom, App);

Lungo.Events.init({
    // 'swipeRight section#home article' : function() {
    // App.Event.tabArticle(this, -1);
    // },
    // 'swipeLeft section#home article' : function() {
    // App.Event.tabArticle(this, 1);
    // },

    // 'swipeRight section' : function() {
    // if (this.id != 'home' && this.id!='question') {
    // App.View.goBack();
    // }
    // },
    // 'swipeRight section#question article' : function() {
    // App.Presenter.QuestionPagePresenter.prevQuestion();
    // },
    // 'swipeLeft section#question article' : function() {
    // App.Presenter.QuestionPagePresenter.nextQuestion();
    // },

});


// ----------src/data/Cache.js----------

/* 
 * 缓存数据
 */
App.Data.Cache = (function() {

    // 所有客户的数据对象
    var customs = [];
    // 不同客户类型的客户索引数组，会重建
    var custom_groups = [];

    return {
        customs: customs,
        custom_groups: custom_groups
    };
})();


// ----------src/data/Constants.js----------

/* 
 * 常量
 */

App.Data.Constants = {
    /**
     * 客户分组类型值
     * @type type
     */
    CUSTOM_GROUP_TYPE:{
        INTENTION:1,
        DEAL:2,
        MONTH:3,
        ALL:4,
        SEARCH:5
    },
    /**
     * 客户分组类型名称
     * @type Array
     */

    DATE_FORMAT:'YYYY-MM-DD HH:MI:SS'
};

// ----------src/data/Element.js----------

/* 
 * 页面组件名称
 */
App.Data.Element = {
    SECTIONS:{
        HOME:'home',
        YELPAGES:'yelpages',
        GROUPING:'grouping',
        CUSTOM:'custom',
        VISIT:'visit'
    },
    ARTICLES:{
    },
    DOMS:{
        HOME:[],
        CUSTOM:{
            custom_name:'input#custom-input-name',
            custom_addr:'input#custom-input-addr',
            person_group:'div#custom-person-group',
            product_group:'div#custom-product-group',
            maturity:'div#custom-maturity',
            visits:'div#custom-visits'
        }
    },
    NAVS:{
    },
    DATA_HEADER:'data-header',
    DATA_NAV:'data-nav'
};

App.Data.Doms = (function (lng) {
    var _ele = App.Data.Element;
    var $ = lng.dom;
    var $_doms = [];

    for (var key in _ele.SECTIONS) {
        var $_section = $('section#' + _ele.SECTIONS[key]);
        var dom_selectors = _ele.DOMS[key];
        if (dom_selectors) {
            var array = [];
            array.section = $_section;
            for (var selector in dom_selectors) {
                array[selector] = $_section.find(dom_selectors[selector]);
            }
            $_doms[key.toLowerCase()] = array;
        }
    }

    return $_doms;

})(Lungo);

// ----------src/data/Template.js----------

/* 
 * 页面组件模板
 */

App.Data.Template = {
    TOOLTIP:'<label class="tooltip">{0}</label>',

    INPUT_GROUP:'<div class="ten columns"><input class="three columns first_input" placeholder="{0}"/><input class="five columns second_input" placeholder="{1}"/></div>',
    INPUT_GROUP_2:'<div class="ten columns"><input class="five columns first_input" placeholder="{0}"/><input class="three columns second_input" placeholder="{1}"/></div>',

    CUSTOM_ITEM:'<li class="selectable" data-index="{3}"><strong>{0}</strong><small class="right">成熟度</small><small>{1}</small><small class="right">{2}</small></li>'

};

// ----------src/service/Protocol.js----------

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




// ----------src/service/Api.js----------

/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




// ----------src/model/Custom.js----------

(function (Model) {
    /**
     * 客户类
     * @type type
     */
    var Custom = (function () {
        function Custom(c_name, c_addr, c_ctime, c_update, c_maturity) {
            this.name = c_name;
            this.addr = c_addr;
            this.persons = new Array();
            this.visits = new Array();
            this.deals = new Array();
            this.lastUpdate = c_update;
            this.createTime = c_ctime;
            this.maturity = c_maturity || 0;
        }

        Custom.TYPE_NONE = 0;           // 未分类（全部）
        Custom.TYPE_THISMONTH = 1;      // 本月
        Custom.TYPE_INTENTION = 2;      // 意向
        Custom.TYPE_DEAL = 3;           // 成交

        Custom.GROUP_TITLE = ["全部客户", "本月客户", "意向客户", "成交客户"];

        Custom.prototype.addPerson = function (p) {
            this.persons.push(p);
        };
        Custom.prototype.addVisit = function (v) {
            this.visits.push(v);
        };
        Custom.prototype.addDeal = function (d) {
            this.deals.push(d);
        };

        /**
         * 是否为本月客户
         * @returns {undefined}
         */
        Custom.prototype.isThisMonth = function () {
            return true;
        };
        /**
         * 是成交用户
         * @returns {undefined}
         */
        Custom.prototype.isDeal = function () {
            return this.deals && this.deals.length > 0;
        };
        /**
         * 是意向用户
         * @returns {undefined}
         */
        Custom.prototype.isIntention = function () {
            return false;
        };

        Custom.buildFromJson = function (data) {
            var custom = new Custom(data.name, data.addr, data.createTime, data.lastUpdate);
            var persons = data.persons;
            var visits = data.visits;
            var deals = data.deals;
            for (var i = 0; i < persons.length; i++) {
                custom.addPerson(Person.buildFromJson(persons[i]));
            }
            for (var i = 0; i < visits.length; i++) {
                custom.addVisit(Visits.buildFromJson(visits[i]));
            }
            for (var i = 0; i < deals.length; i++) {
                custom.addDeal(Deal.buildFromJson(deals[i]));
            }
            return custom;
        };
        return Custom;
    })();
    Model.Custom = Custom;
    /**
     * 联系人类
     * @type type
     */
    var Person = (function () {
        function Person(p_name, p_tel) {
            this.name = p_name;
            this.tel = p_tel;
        }

        Person.buildFromJson = function (data) {
            return new Person(data.name, data.tel);
        };
        return Person;
    })();
    Model.Person = Person;
    /**
     * 拜访记录类
     * @type type
     */
    var Visit = (function () {
        function Visit(v_pname, v_content, v_time, v_maturity) {
            this.person_name = v_pname;
            this.content = v_content;
            this.time = v_time;
            this.maturity = v_maturity;
        }

        Visit.buildFromJson = function (data) {
            return new Visit(data.person_name, data.content, data.time, data.maturity);
        };
        return Visit;
    })();
    Model.Visit = Visit;
    /**
     * 成交记录类
     * @type type
     */
    var Deal = (function () {
        function Deal(d_product, d_money, d_time) {
            this.product = d_product;
            this.money = d_money;
            this.time = d_time;
        }

        Deal.buildFromJson = function (data) {
            return new Deal(data.product, data.money, data.time);
        };
        return Deal;
    })();
    Model.Deal = Deal;
})(App.Model || (App.Model = {}));

// ----------src/biz/CustomBiz.js----------

App.Biz.CustomBiz = (function (App) {

    var _CUSTOMS_CACHE_KEY = 'ALL_CUSTOMS';
    var _Custom = App.Model.Custom;
    var _cache = App.Data.Cache;

    var loadCustomData = function () {
        var data = getstorage(_CUSTOMS_CACHE_KEY);
        var customs = [];
        if (data) {
            var list = JSON.parse(data);
            for (var i = 0; i < list.length; i++) {
                customs[i] = _Custom.buildFromJson(list[i]);
            }
        }
        return customs;
    };

    var saveCustomData = function (customs) {
        var data = JSON.stringify(customs);
        if (data) {
            setstorage(_CUSTOMS_CACHE_KEY, data);
            return true;
        }
        return false;
    };

    /**
     * 分组客户类型
     * @param customs
     */
    var computeCustomGroup = function (customs) {
        var groups = [];
        groups[_Custom.TYPE_THISMONTH] = [];
        groups[_Custom.TYPE_INTENTION] = [];
        groups[_Custom.TYPE_DEAL] = [];
        for (var i = 0; i < customs.length; i++) {
            _pushCustomToGroup(groups, customs[i]);
        }
        return groups;
    };

    var _pushCustomToGroup = function (groups, custom) {
        if (custom.isThisMonth()) {
            groups[_Custom.TYPE_THISMONTH].push(custom);
        }
        if (custom.isDeal()) {
            groups[_Custom.TYPE_DEAL].push(custom);
        }
        if (custom.isIntention()) {
            groups[_Custom.TYPE_INTENTION].push(custom);
        }
    };

    var appendCustom = function (custom) {
        var customs = _cache.customs;
        customs.push(custom);
        _pushCustomToGroup(_cache.custom_groups, custom);
        saveCustomData(customs);
    };

    var getCustomGroupByType = function (type) {
        return type === _Custom.TYPE_NONE ? _cache.customs : _cache.custom_groups[type];
    };

    return{
        loadCustomData:loadCustomData,
        saveCustomData:saveCustomData,
        computeCustomGroup:computeCustomGroup,
        appendCustom:appendCustom,
        getCustomGroupByType:getCustomGroupByType
    }

})(App);

// ----------src/biz/Rules.js----------

App.Biz.Rules = (function () {

    var _cont = App.Data.Constants;

    var now = function () {
        return new Date().toFomatorString(_cont.DATE_FORMAT);
    };
    return {
        now:now
    }
})();


// ----------src/View.js----------

App.View = (function(lng, App) {

    var $ = lng.dom;
    var _element = App.Data.Element;
    var _onPageChange = [];
    var _sections = [];

    /**
     * 注册一个页面切换时的函数钩
     * @param {type} key
     * @param {type} func
     * @returns {undefined}
     */
    var registerPageChangeFunc = function(key, func) {
        _onPageChange[key] = func;
    };

    var showConfirm = function(content, first_label, first_callback, second_label, second_callback) {
        var notif = {
            title: '提示',
            description: content,
            accept: {
                color: 'blue',
                label: first_label,
                callback: first_callback
            },
            cancel: {
                color: 'blue',
                label: second_label,
                callback: second_callback
            }
        };
        lng.Notification.confirm(notif);
    };

    // remove section
    var pushCachePage = function(section) {
        section = section || lng.Element.Cache.section;
        if (section && section[0]) {
            var section_id = section[0].id;
            if (section_id) {
                _sections["#" + section_id] = section[0];
            }
            window.setTimeout(function() {
                section.remove();
            }, 200);
        }
    };

    // add section to body
    var pullCachePage = function(section_id) {
        var $_section = $("section" + section_id);
        if (!$_section || $_section.length === 0) {
            var section = _sections[section_id];
            $("body").append(section);
            _sections[section_id] = '';
        }
    };

    /**
     * 设置页面基础组件
     * @param {type} article_id
     * @returns {undefined}
     */
    var showPage = function(article_id) {
        var $_page = $('#' + article_id);
        var dom_page = $_page[0];
        if (dom_page) {
            var parent = $_page.parent();
            var header = $_page.attr(_element.DATA_HEADER);
            _setHeader(parent, header);
            var nav = $_page.attr(_element.DATA_NAV);
            _setNav(parent, nav);
            // 某些页面需要在切换时的函数钩
            for (var key in _onPageChange) {
                _onPageChange[key] && _onPageChange[key](article_id);
            }
        }
    };

    var _setHeader = function(parent, header) {
        var headers = parent.find('header');
        headers.hide();
        var current = headers.first();
        if (header) {
            current = parent.find('header#' + header);
        }
        current && current.show();
    };

    var _setNav = function(parent, nav) {
        var navs = parent.find('nav.hnav');
        _cacheNavs(navs);
        navs.remove();
        if (nav) {
            //var current = parent.find('nav.hnav#' + nav);
            var current = _hnavs[nav];
            if (current) {
                parent.append(current);
            }
        }
    };

    var _hnavs = [];
    var _cacheNavs = function(hnavs) {
        for (var i in hnavs) {
            var id = hnavs[i].id;
            _hnavs[id] = hnavs[i];
        }
    };

    return {
        showPage: showPage,
        registerPageChangeFunc: registerPageChangeFunc,
        showConfirm: showConfirm,
        pushCachePage: pushCachePage,
        pullCachePage: pullCachePage
    };
})(Lungo, App);

App.View.Helper = (function(lng) {

    var setTitle = function(title) {
        if (title.length > 10) {
            title = title.substring(0, 10) + '...';
        }
        lng.View.Article.title(title);
    };

    var createElement = function(content) {
        var div;
        div = document.createElement("div");
        div.innerHTML = content;
        return div.firstChild;
    };

    return {
        setTitle: setTitle,
        createElement: createElement
    };

})(Lungo);

// ----------src/view/CustomPage.js----------

var PAGE_CUSTOM = 'art-custom';
/**
 * 客户详情页
 * @type _L5.Anonym$0
 */
App.View.CustomPage = (function (lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;
    var _ele = App.Data.Element;

    var $ = lng.dom;
    var $_doms = App.Data.Doms[_ele.SECTIONS.CUSTOM];
    var $_section = $_doms.section;
    var $_maturity = $_doms.maturity;
    var $_visits = $_doms.visits;

    var loadPage = function () {

    };

    var showAddCustom = function () {
        _cleanPage();
        $_maturity.hide();
        $_visits.hide();
    };

    var showCustomDetails = function (custom) {
        _cleanPage();
        _setCustomDetails(custom);
        $_maturity.show();
        $_visits.show();
    };

    /**
     * 清理页面
     * @private
     */
    var _cleanPage = function () {
        $_doms.custom_name.val('');
        $_doms.custom_addr.val('');
        $_doms.person_group.find('div').remove();
        $_doms.product_group.find('div').remove();
    };

    /**
     * 显示客户
     * @param custom
     * @private
     */
    var _setCustomDetails = function (custom) {
        $_doms.custom_name.val(custom.name);
        $_doms.custom_addr.val(custom.addr);
        _setPersonInputs(custom.persons);
        _setDealInputs(custom.deals);
    };

    var _setPersonInputs = function (persons) {
        var size = persons.length;
        for (var i = size; --i >= 0;) {
            $_doms.person_group.append(_template.INPUT_GROUP.format('联系人', '联系方式'));
        }
        var nameDoms = $_doms.person_group.find('.first_input');
        var telDoms = $_doms.person_group.find('.second_input');
        for (var i = 0; i < size; i++) {
            nameDoms[i].value = persons[i].name;
            telDoms[i].value = persons[i].tel;
        }
    };

    var _setDealInputs = function (deals) {
        var size = deals.length;
        for (var i = size; --i >= 0;) {
            $_doms.product_group.append(_template.INPUT_GROUP_2.format('产品', '金额'));
        }
        var productDoms = $_doms.product_group.find('.first_input');
        var moneyDoms = $_doms.product_group.find('.second_input');
        for (var i = 0; i < size; i++) {
            productDoms[i].value = deals[i].product;
            moneyDoms[i].value = deals[i].money;
        }
    };

    return {
        loadPage:loadPage,
        showAddCustom:showAddCustom,
        showCustomDetails:showCustomDetails
    };
})(Lungo, App);

// ----------src/view/GroupingPage.js----------

var PAGE_GROUPING = 'art-grouping';
/**
 * 客户分组搜索页
 * @type _L5.Anonym$0
 */
App.View.GroupingPage = (function (lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;
    var _element = App.Data.Element;

    var $ = lng.dom;
    var $_section = $('section#' + _element.SECTIONS.GROUPING);
    var $_search_input = $_section.find('input#grouping-input-search');
    var $_grouping_list = $_section.find('ul#grouping-list');

    var loadPage = function () {

    };

    var buildCustomList = function (customs) {
        var div = '';
        for (var i = 0; i < customs.length; i++) {
            var custom = customs[i];
            div += _template.CUSTOM_ITEM.format(custom.name, custom.lastUpdate, custom.maturity, i);
        }
        if (div.isEmpty()) {
            div = _template.TOOLTIP.format("暂无客户");
        }
        $_grouping_list.html(div);
    };

    var bindListItems = function (call) {
        $_grouping_list.find('li').bind('touchend', function (e) {
            var index = this.getAttribute("data-index");
            call(index);
        });
    };

    var setSearchKeyword = function (keyword) {
        $_search_input.val(keyword);
    };

    return {
        loadPage:loadPage,
        setSearchKeyword:setSearchKeyword,
        buildCustomList:buildCustomList,
        bindListItems:bindListItems
    };
})(Lungo, App);

// ----------src/view/HomeCustomPage.js----------

var PAGE_HOME_CUSTOM = 'art-home-custom';
/**
 * 主页客户分页
 * @type _L5.Anonym$0
 */
App.View.HomeCustomPage = (function (lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;

    var $ = lng.dom;
    var $_section = $('section#home');
    var $_span_all = $_section.find('#home-custom-all');
    var $_span_month = $_section.find('#home-custom-month');
    var $_span_intention = $_section.find('#home-custom-intention');
    var $_span_deal = $_section.find('#home-custom-deal');

    var loadPage = function () {

    };

    var setSpanNumber = function (all, month, intention, deal) {
        $_span_all.html(all);
        $_span_month.html(month);
        $_span_intention.html(intention);
        $_span_deal.html(deal);
    };

    return {
        loadPage:loadPage,
        setSpanNumber:setSpanNumber
    };
})(Lungo, App);

// ----------src/view/HomeInfoPage.js----------

var PAGE_HOME_INFO = 'art-home-info';
/**
 * 主页信息页
 * @type _L5.Anonym$0
 */
App.View.HomeInfoPage = (function(lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;

    var $ = lng.dom;
    var $_loader = $('nav#home-loader');
    var $_alerter = $('label#home-alerter');
    var $_content = $('ul#home-content');
    var $_shortbar = $('div#home-float-shortbar');

    var loadPage = function() {

    };

    var showPageAlert = function(msg) {
        $_content.hide();
        $_alerter.html(msg);
        $_alerter.show();
    };

    var showPageContent = function() {
        $_alerter.hide();
        $_content.show();
    };

    var setLoaderVisiable = function(isVisiable) {
        if (isVisiable) {
            $_loader.show();
        } else {
            $_loader.hide();
        }
    };

    var toggleFloatShortbar = function() {
        if ($_shortbar.style('display') !== 'none') {
            $_shortbar.hide();
        } else {
            $_shortbar.show();
        }
    };

    var _onPageChange = function() {
        if ($_shortbar.style('display') !== 'none') {
            $_shortbar.hide();
        }
    };

    // 注册函数钩
    App.View.registerPageChangeFunc(PAGE_HOME_INFO, _onPageChange);

    return {
        loadPage: loadPage,
        showPageAlert: showPageAlert,
        setLoaderVisiable: setLoaderVisiable,
        showPageContent: showPageContent,
        toggleFloatShortbar: toggleFloatShortbar
    };
})(Lungo, App);

// ----------src/view/HomeMorePage.js----------

var PAGE_HOME_MORE = 'art-home-more';
/**
 * 主页更多
 * @type _L5.Anonym$0
 */
App.View.HomeMorePage = (function(lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;

    var $ = lng.dom;
    var $_loader = $('nav#home-loader');
    var $_alerter = $('label#home-alerter');
    var $_content = $('ul#home-content');

    var loadPage = function() {

    };

    var showPageAlert = function(msg) {
        $_content.hide();
        $_alerter.html(msg);
        $_alerter.show();
    };

    var showPageContent = function() {
        $_alerter.hide();
        $_content.show();
    };

    var setLoaderVisiable = function(isVisiable) {
        if (isVisiable) {
            $_loader.show();
        } else {
            $_loader.hide();
        }
    };

    return {
        loadPage: loadPage,
        showPageAlert: showPageAlert,
        setLoaderVisiable: setLoaderVisiable,
        showPageContent: showPageContent
    };
})(Lungo, App);

// ----------src/view/HomeRaidPage.js----------

var PAGE_HOME_RAID = 'art-home-raid';
/**
 * 主页团队页
 * @type _L5.Anonym$0
 */
App.View.HomeRaidPage = (function(lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;

    var $ = lng.dom;
    var $_loader = $('nav#home-loader');
    var $_alerter = $('label#home-alerter');
    var $_content = $('ul#home-content');

    var loadPage = function() {

    };

    var showPageAlert = function(msg) {
        $_content.hide();
        $_alerter.html(msg);
        $_alerter.show();
    };

    var showPageContent = function() {
        $_alerter.hide();
        $_content.show();
    };

    var setLoaderVisiable = function(isVisiable) {
        if (isVisiable) {
            $_loader.show();
        } else {
            $_loader.hide();
        }
    };

    return {
        loadPage: loadPage,
        showPageAlert: showPageAlert,
        setLoaderVisiable: setLoaderVisiable,
        showPageContent: showPageContent
    };
})(Lungo, App);

// ----------src/view/MemberPage.js----------

var PAGE_MEMBER = 'art-member';
/**
 * 人员统计页
 * @type _L5.Anonym$0
 */
App.View.MemberPage = (function(lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;

    var $ = lng.dom;
    var $_loader = $('nav#home-loader');
    var $_alerter = $('label#home-alerter');
    var $_content = $('ul#home-content');

    var loadPage = function() {

    };

    var showPageAlert = function(msg) {
        $_content.hide();
        $_alerter.html(msg);
        $_alerter.show();
    };

    var showPageContent = function() {
        $_alerter.hide();
        $_content.show();
    };

    var setLoaderVisiable = function(isVisiable) {
        if (isVisiable) {
            $_loader.show();
        } else {
            $_loader.hide();
        }
    };

    return {
        loadPage: loadPage,
        showPageAlert: showPageAlert,
        setLoaderVisiable: setLoaderVisiable,
        showPageContent: showPageContent
    };
})(Lungo, App);

// ----------src/view/VisitPage.js----------

var PAGE_VISIT = 'art-visit';
/**
 * 拜访记录页
 * @type _L5.Anonym$0
 */
App.View.VisitPage = (function(lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;

    var $ = lng.dom;
    var $_loader = $('nav#home-loader');
    var $_alerter = $('label#home-alerter');
    var $_content = $('ul#home-content');

    var loadPage = function() {

    };

    var showPageAlert = function(msg) {
        $_content.hide();
        $_alerter.html(msg);
        $_alerter.show();
    };

    var showPageContent = function() {
        $_alerter.hide();
        $_content.show();
    };

    var setLoaderVisiable = function(isVisiable) {
        if (isVisiable) {
            $_loader.show();
        } else {
            $_loader.hide();
        }
    };

    return {
        loadPage: loadPage,
        showPageAlert: showPageAlert,
        setLoaderVisiable: setLoaderVisiable,
        showPageContent: showPageContent
    };
})(Lungo, App);

// ----------src/view/YelpagesPage.js----------

var PAGE_YELPAGES = 'art-yelpages';
/**
 * 客户黄页
 * @type _L5.Anonym$0
 */
App.View.YelpagesPage = (function(lng, App) {

    var _router = App.Router;
    var _template = App.Data.Template;

    var $ = lng.dom;
    var $_loader = $('nav#home-loader');
    var $_alerter = $('label#home-alerter');
    var $_content = $('ul#home-content');

    var loadPage = function() {

    };

    var showPageAlert = function(msg) {
        $_content.hide();
        $_alerter.html(msg);
        $_alerter.show();
    };

    var showPageContent = function() {
        $_alerter.hide();
        $_content.show();
    };

    var setLoaderVisiable = function(isVisiable) {
        if (isVisiable) {
            $_loader.show();
        } else {
            $_loader.hide();
        }
    };

    return {
        loadPage: loadPage,
        showPageAlert: showPageAlert,
        setLoaderVisiable: setLoaderVisiable,
        showPageContent: showPageContent
    };
})(Lungo, App);

// ----------src/Presenter.js----------

App.Presenter = (function() {

    var _presenters = [];

    var getPresenters = function() {
        return _presenters;
    };

    var register = function(page_id, presenter) {
        _presenters[page_id] = presenter;
    };

    var loadPanel = function(id) {
        var presenter = _presenters[id];
        if (presenter && presenter.onLoad) {
            presenter.onLoad(id);
        }
    };

    return {
        register: register,
        getPresenters: getPresenters,
        loadPanel: loadPanel
    };
})();



// ----------src/Router.js----------

/**
 * 应用页面跳转路由器
 * @type type
 */
App.Router = (function(lng) {

    var _view = App.View;
    var _presenter = App.Presenter;
    var CLASS_CURRENT = 'current';

    /**
     * 
     * @param {String} section_id
     * @returns {undefined}
     */
    var gotoSection = function(section_id) {
        var section_code = '#' + section_id;
        if (!lng.Router.backTo(section_code, _onTrigger)) {
            _onTrigger(null, section_code);
            _onTrigger(null);
            lng.Router.section(section_id);
        }
    };

    /**
     * 
     * @param {type} section_id
     * @param {type} article_id
     * @param {type} nav id
     * @param {type} loadData
     * @returns {undefined}
     */
    var gotoArticle = function(section_id, article_id, nav_id, loadData) {
        gotoSection(section_id, true);
        lng.Router.article(section_id, article_id);
        _view.showPage(article_id);
        nav_id && showNavItem(nav_id);
        window.setTimeout(function() {
            _presenter.loadPanel(article_id);
            loadData && loadData();
        }, 200);
    };

    /**
     * 
     * @returns {undefined}
     */
    var goBack = function() {
        lng.Router.back(_onTrigger);
        _presenter.loadPanel(lng.Element.Cache.article[0].id);
    };

    /**
     * on section trigger, push or pull section
     * 
     * @param {type} section
     * @param {type} target_id
     * @returns {undefined}
     */
    var _onTrigger = function(section, target_id) {
        if (!target_id) {
            _view.pushCachePage(section);
        } else {
            _view.pullCachePage(target_id);
        }
    };

    /**
     * 
     * @param {type} nav
     * @param {type} fnav
     * @returns {undefined}
     */
    var showNavItem = function(navs, hnav) {
        var fnav = navs;
        if ((navs instanceof Array) && navs.length > 1) {
            fnav = navs[0];
            hnav = navs[1];
        }
        if (fnav) {
            // remove current nav style
            var navs = lng.Element.Cache.section.find('a[href][data-router="nav"]');
            navs && navs.removeClass(CLASS_CURRENT);
            // set new nav style
            lng.dom('#' + fnav).addClass(CLASS_CURRENT);
        }
        if (hnav) {
            // set footer nav style
            lng.dom('#' + hnav).addClass(CLASS_CURRENT);
        }
    };

    return {
        gotoSection: gotoSection,
        gotoArticle: gotoArticle,
        goBack: goBack,
        showNavItem: showNavItem
    };
})(Lungo);

// ----------src/presenter/CustomPagePresenter.js----------

App.Presenter.CustomPagePresenter = (function (App) {

    var _router = App.Router;
    var _page = App.View.CustomPage;
    var _view = App.View;
    var _cache = App.Data.Cache;

    // 页面操作类型
    var ACTION_TYPE = {
        DETAILS:0, // 客户详情
        ADD:1              // 添加客户
    };
    var _action;
    var _custom;

    var onLoad = function (page_id) {
        _page.loadPage(page_id);
    };

    var setData = function (data) {
        if (data) {
            _action = data.action || ACTION_TYPE.DETAILS;
            _custom = data.custom;
            _parseAction();
        }
    };

    var _parseAction = function () {
        switch (_action) {
            case ACTION_TYPE.DETAILS:
                _view.Helper.setTitle('客户详情');
                _page.showCustomDetails(_custom);
                break;
            case ACTION_TYPE.ADD:
                _view.Helper.setTitle('添加客户');
                _page.showAddCustom();
                break;
        }
    };

    return {
        ACTION_TYPE:ACTION_TYPE,
        onLoad:onLoad,
        setData:setData
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_CUSTOM, App.Presenter.CustomPagePresenter);

// ----------src/presenter/GroupingPagePresenter.js----------

App.Presenter.GroupingPagePresenter = (function (App) {

    var _router = App.Router;
    var _page = App.View.GroupingPage;
    var _view = App.View;
    var _cache = App.Data.Cache;
    var _cont = App.Data.Constants;
    var _Custom = App.Model.Custom;
    var _customBiz = App.Biz.CustomBiz;
    var _element = App.Data.Element;
    var _presenter = App.Presenter;

    // 分组类型
    var _type = 0;
    var _customs = [];

    var onLoad = function (page_id) {
        _page.loadPage(page_id);
    };

    var setData = function (data) {
        if (data) {
            _type = data.type;
            _customs = _customBiz.getCustomGroupByType(_type);
            if (data.keyword) {
                _view.Helper.setTitle('搜索客户');
                _page.setSearchKeyword(data.keyword);
            } else {
                _view.Helper.setTitle(_Custom.GROUP_TITLE[_type]);
            }
            _page.buildCustomList(_customs);
            _page.bindListItems(_onClickCustomItem);
        }
    };

    var _onClickCustomItem = function (index) {
        _customs[index] && enterCustom(_customs[index]);
    };

    var enterCustom = function (custom) {
        _router.gotoArticle(_element.SECTIONS.CUSTOM, PAGE_CUSTOM);
        _presenter.CustomPagePresenter.setData({
            action:_presenter.CustomPagePresenter.ACTION_TYPE.DETAILS,
            custom:custom
        });
    };

    return {
        onLoad:onLoad,
        setData:setData
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_GROUPING, App.Presenter.GroupingPagePresenter);

// ----------src/presenter/HomeCustomPagePresenter.js----------

App.Presenter.HomeCustomPagePresenter = (function (App) {

    var _router = App.Router;
    var _page = App.View.HomeCustomPage;
    var _cache = App.Data.Cache;
    var _Custom = App.Model.Custom;

    var onLoad = function (page_id) {
        _page.loadPage(page_id);
        _computeCustomGroupAndShow();
    };

    var _computeCustomGroupAndShow = function () {
        var all = _cache.customs.length;
        var groups = _cache.custom_groups;
        _page.setSpanNumber(all, groups[_Custom.TYPE_THISMONTH].length, groups[_Custom.TYPE_INTENTION].length, groups[_Custom.TYPE_DEAL].length);
    };

    return {
        onLoad:onLoad
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_HOME_CUSTOM, App.Presenter.HomeCustomPagePresenter);

// ----------src/presenter/HomeInfoPagePresenter.js----------

App.Presenter.HomeInfoPagePresenter = (function (App) {

    var _router = App.Router;
    var _page = App.View.HomeInfoPage;
    var _cache = App.Data.Cache;

    var onLoad = function (page_id) {
        _page.loadPage(page_id);

    };


    return {
        onLoad:onLoad
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_HOME_INFO, App.Presenter.HomeInfoPagePresenter);

// ----------src/presenter/HomeMorePagePresenter.js----------

App.Presenter.HomeMorePagePresenter = (function(App) {

    var _router = App.Router;
    var _page = App.View.HomeMorePage;
    var _cache = App.Data.Cache;

    var onLoad = function(page_id) {
        _page.loadPage(page_id);
    };

    return {
        onLoad: onLoad
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_HOME_MORE, App.Presenter.HomeMorePagePresenter);

// ----------src/presenter/HomeRaidPagePresenter.js----------

App.Presenter.HomeRaidPagePresenter = (function(App) {

    var _router = App.Router;
    var _page = App.View.HomeRaidPage;
    var _cache = App.Data.Cache;

    var onLoad = function(page_id) {
        _page.loadPage(page_id);
    };

    return {
        onLoad: onLoad
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_HOME_RAID, App.Presenter.HomeRaidPagePresenter);

// ----------src/presenter/MemberPagePresenter.js----------

App.Presenter.MemberPagePresenter = (function(App) {

    var _router = App.Router;
    var _page = App.View.MemberPage;
    var _cache = App.Data.Cache;

    var onLoad = function(page_id) {
        _page.loadPage(page_id);
    };

    return {
        onLoad: onLoad
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_MEMBER, App.Presenter.MemberPagePresenter);

// ----------src/presenter/VisitPagePresenter.js----------

App.Presenter.VisitPagePresenter = (function(App) {

    var _router = App.Router;
    var _page = App.View.VisitPage;
    var _cache = App.Data.Cache;

    var onLoad = function(page_id) {
        _page.loadPage(page_id);
    };

    return {
        onLoad: onLoad
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_VISIT, App.Presenter.VisitPagePresenter);

// ----------src/presenter/YelpagesPagePresenter.js----------

App.Presenter.YelpagesPagePresenter = (function(App) {

    var _router = App.Router;
    var _page = App.View.YelpagesPage;
    var _cache = App.Data.Cache;

    var onLoad = function(page_id) {
        _page.loadPage(page_id);
    };

    return {
        onLoad: onLoad
    };

})(App);

// 注册展示器
App.Presenter.register(PAGE_YELPAGES, App.Presenter.YelpagesPagePresenter);

// ----------src/Binder.js----------

App.Binder = (function(lng, App) {

    var $ = lng.dom;
    var section_binder = [];

    /**
     * 页面预定义的组件绑定加载(通过binder)
     * @param {type} bind_list
     * @returns {undefined}
     */
    var bindData = function(bind_list) {
        var list = bind_list || section_binder;
        for (var key in list) {
            var data = list[key];
            bindToSection(key, data);
        }
        $('a.icon-back').bind('touchend', App.Router.goBack);
    };

    /**
     * 批量增加某个section页的组件绑定
     * @param {type} section_id
     * @param {type} bind_list
     * @returns {undefined}
     */
    var bindToSection = function(section_id, bind_list) {
        var selector_page = 'section#' + section_id;
        var $_page = $(selector_page);
        for (var selector in bind_list) {
            var $_div = $_page.find(selector);
            // 使用touchend比click响应快速
            $_div.bind('touchend', bind_list[selector]);
        }
    };

    return{
        section_binder: section_binder,
        bindData: bindData,
        bindToSection: bindToSection
    };

})(Lungo, App);

// ----------src/binder/CustomPageBinder.js----------

/**
 * 绑定home页面的点击事件
 * @param {type} lng
 * @param {type} App
 * @returns {undefined}
 */
(function (lng, App) {

    var _router = App.Router;
    var _view = App.View;
    var _presenter = App.Presenter;
    var _element = App.Data.Element;
    var _cont = App.Data.Constants;
    var _binder = App.Binder;
    var _template = App.Data.Template;
    var _biz = App.Biz;
    var _Custom = App.Model.Custom;
    var _Person = App.Model.Person;
    var _Deal = App.Model.Deal;

    var $ = lng.dom;
    var $_doms = App.Data.Doms[_element.SECTIONS.CUSTOM];
    var $_section = $_doms.section;
    var $_person_group = $_doms.person_group;
    var $_product_group = $_doms.product_group;
    var $_custom_name = $_doms.custom_name;
    var $_custom_addr = $_doms.custom_addr;

    var _saveCustom = function () {
        var time = _biz.Rules.now();
        var custom;
        var custom_name = $_custom_name.val();
        var custom_addr = $_custom_addr.val();
        if (!custom_name.isEmpty() && !custom_addr.isEmpty()) {
            custom = new _Custom(custom_name, custom_addr, time, time);
        } else {
            // 客户名称或地址不能为空
            return;
        }
        // add persons
        var person_names = $_person_group.find('.first_input');
        var person_tels = $_person_group.find('.second_input');
        var size = person_names.length;
        for (var i = 0; i < size; i++) {
            var person_name = person_names[i].value;
            var person_tel = person_tels[i].value;
            if (!person_name.isEmpty() && !person_tel.isEmpty()) {
                custom.addPerson(new _Person(person_name, person_tel));
            }
        }
        // add products
        var product_names = $_product_group.find('.first_input');
        var product_moneys = $_person_group.find('.second_input');
        var size = product_names.length;
        for (var i = 0; i < size; i++) {
            var product_name = product_names[i].value;
            var product_money = product_moneys[i].value;
            if (!product_name.isEmpty() && !product_money.isEmpty()) {
                custom.addDeal(new _Deal(product_name, product_money, time));
            }
        }
        _biz.CustomBiz.appendCustom(custom);
    };

    _binder.section_binder[_element.SECTIONS.CUSTOM] = {
        'a#custom-btn-save':_saveCustom,
        'a#custom-add-person':function () {
            $_person_group.append(_template.INPUT_GROUP.format('联系人', '联系方式'));
        },
        'a#custom-add-product':function () {
            $_product_group.append(_template.INPUT_GROUP_2.format('产品', '金额'));
        },
        'a#custom-add-visit':function () {

        }
    };
})(Lungo, App);

// ----------src/binder/GroupingPageBinder.js----------

/**
 * 绑定home页面的点击事件
 * @param {type} lng
 * @param {type} App
 * @returns {undefined}
 */
(function(lng, App) {

    var _router = App.Router;
    var _view = App.View;
    var _presenter = App.Presenter;
    var _element = App.Data.Element;
    var _cont = App.Data.Constants;
    var _binder = App.Binder;
    var $ = lng.dom;

    _binder.section_binder[_element.SECTIONS.GROUPING] = {
    };
})(Lungo, App);

// ----------src/binder/HomePageBinder.js----------

/**
 * 绑定home页面的点击事件
 * @param {type} lng
 * @param {type} App
 * @returns {undefined}
 */
(function (lng, App) {

    var _router = App.Router;
    var _view = App.View;
    var _presenter = App.Presenter;
    var _element = App.Data.Element;
    var _binder = App.Binder;
    var _Custom = App.Model.Custom;
    var $ = lng.dom;

    _binder.section_binder[_element.SECTIONS.HOME] = {
        // the header nav
        'a#home-hnav-yelpages':function () {
            _router.gotoArticle(_element.SECTIONS.YELPAGES, PAGE_YELPAGES);
        },
        // the footer nav
        'a#home-fnav-info':function () {
            _router.gotoArticle('home', PAGE_HOME_INFO, 'home-fnav-info');
        },
        'a#home-fnav-custom':function () {
            _router.gotoArticle('home', PAGE_HOME_CUSTOM, ['home-fnav-custom', 'home-hnav-mycustom']);
        },
        'a#home-fnav-raid':function () {
            _router.gotoArticle('home', PAGE_HOME_RAID, 'home-fnav-raid');
        },
        'a#home-fnav-more':function () {
            _router.gotoArticle('home', PAGE_HOME_MORE, 'home-fnav-more');
        },
        'a#home-fnav-add':function () {
            _view.HomeInfoPage.toggleFloatShortbar();
        },
        // the shortbar
        'a#home-shortbar-intention':function () {
            _router.gotoArticle(_element.SECTIONS.GROUPING, PAGE_GROUPING);
            _presenter.GroupingPagePresenter.setData({
                type:_Custom.TYPE_INTENTION
            });
        },
        'a#home-shortbar-addcustom':function () {
            _router.gotoArticle(_element.SECTIONS.CUSTOM, PAGE_CUSTOM);
            _presenter.CustomPagePresenter.setData({
                action:_presenter.CustomPagePresenter.ACTION_TYPE.ADD
            });
        },
        'a#home-shortbar-addvisit':function () {
            _router.gotoArticle(_element.SECTIONS.VISIT, PAGE_VISIT);
        },
        // the info page
        'a#home-info-intention':function () {
            // 马上成交
            _router.gotoArticle(_element.SECTIONS.GROUPING, PAGE_GROUPING);
            _presenter.GroupingPagePresenter.setData({
                type:_Custom.TYPE_INTENTION
            });
        },
        'a#home-info-edit':function () {
            // 编辑月度目标
            // 隐藏编辑
            var $_mouth_target = $('label#home-month-target-label');
            var mouth_target = $_mouth_target.html();
            $_mouth_target.hide();
            $('a#home-info-edit').hide();

            // 显示输入框
            var $_mouth_target_input = $('input#home-month-target-input');
            $_mouth_target_input.val(mouth_target);
            $_mouth_target_input.show();
            $('a#home-info-save').show();
        },
        'a#home-info-save':function () {
            // 编辑月度目标

            var $_mouth_target_input = $('input#home-month-target-input');
            var mouth_target = $_mouth_target_input.val();
            //$_mouth_target_input.val(mouth_target);
            $_mouth_target_input.hide();
            $('a#home-info-save').hide();

            var $_mouth_target = $('label#home-month-target-label');
            $_mouth_target.html(mouth_target);
            $_mouth_target.show();
            $('a#home-info-edit').show();
        },
        // the custom page
        // 添加客户按钮
        'a#home-custom-add':function () {
            _router.gotoArticle(_element.SECTIONS.CUSTOM, PAGE_CUSTOM);
            _presenter.CustomPagePresenter.setData({
                action:_presenter.CustomPagePresenter.ACTION_TYPE.ADD
            });
        },
        'a#home-search-custom':function () {
            // 搜索客户
            var keyword = $('input#home-input-search').val();
            _router.gotoArticle(_element.SECTIONS.GROUPING, PAGE_GROUPING);
            _presenter.GroupingPagePresenter.setData({
                type:_Custom.TYPE_NONE,
                keyword:keyword
            });
        },
        'a#home-custom-intention-btn':function () {
            // 意向客户
            _router.gotoArticle(_element.SECTIONS.GROUPING, PAGE_GROUPING);
            _presenter.GroupingPagePresenter.setData({
                type:_Custom.TYPE_INTENTION
            });
        },
        'a#home-custom-deal-btn':function () {
            // 成交客户
            _router.gotoArticle(_element.SECTIONS.GROUPING, PAGE_GROUPING);
            _presenter.GroupingPagePresenter.setData({
                type:_Custom.TYPE_DEAL
            });
        },
        'a#home-custom-month-btn':function () {
            // 本月客户
            _router.gotoArticle(_element.SECTIONS.GROUPING, PAGE_GROUPING);
            _presenter.GroupingPagePresenter.setData({
                type:_Custom.TYPE_THISMONTH
            });
        },
        'a#home-custom-all-btn':function () {
            // 全部客户
            _router.gotoArticle(_element.SECTIONS.GROUPING, PAGE_GROUPING);
            _presenter.GroupingPagePresenter.setData({
                type:_Custom.TYPE_NONE
            });
        }
    };
})(Lungo, App);

// ----------src/binder/MemberPageBinder.js----------

/**
 * 绑定home页面的点击事件
 * @param {type} lng
 * @param {type} App
 * @returns {undefined}
 */
(function(lng, App) {

    var _router = App.Router;
    var _view = App.View;
    var _presenter = App.Presenter;
    var _element = App.Data.Element;
    var _cont = App.Data.Constants;
    var _binder = App.Binder;
    var $ = lng.dom;

    _binder.section_binder[_element.SECTIONS.MEMBER] = {
    };
})(Lungo, App);

// ----------src/binder/VisitPageBinder.js----------

/**
 * 绑定home页面的点击事件
 * @param {type} lng
 * @param {type} App
 * @returns {undefined}
 */
(function(lng, App) {

    var _router = App.Router;
    var _view = App.View;
    var _presenter = App.Presenter;
    var _element = App.Data.Element;
    var _cont = App.Data.Constants;
    var _binder = App.Binder;
    var $ = lng.dom;

    _binder.section_binder[_element.SECTIONS.VISIT] = {
    };
})(Lungo, App);

// ----------src/binder/YelpagesPageBinder.js----------

/**
 * 绑定home页面的点击事件
 * @param {type} lng
 * @param {type} App
 * @returns {undefined}
 */
(function(lng, App) {

    var _router = App.Router;
    var _view = App.View;
    var _presenter = App.Presenter;
    var _element = App.Data.Element;
    var _cont = App.Data.Constants;
    var _binder = App.Binder;
    var $ = lng.dom;

    _binder.section_binder[_element.SECTIONS.YELPAGES] = {
    };
})(Lungo, App);

// ----------src/Init.js----------

Lungo.init({
    name:'Webapp'
});
Lungo.ready(function () {

    /**
     * 读取缓存数据
     */
    var catchCacheData = function () {
        var _cache = App.Data.Cache;
        var _customBiz = App.Biz.CustomBiz;
        _cache.customs = _customBiz.loadCustomData();
        _cache.custom_groups = _customBiz.computeCustomGroup(_cache.customs);
    };

    window.setTimeout(function () {
        App.Router.gotoArticle('home', PAGE_HOME_INFO);
    }, 1000);
    App.Binder.bindData();
    pushPageSections();
    catchCacheData();
});

var pushPageSections = function () {
    var $ = Lungo.dom;
    var sections = $('body > section');
    for (var i = 0; i < sections.length; i++) {
        var section_id = sections[i].id;
        if (section_id && section_id !== 'loading') {
            App.View.pushCachePage($('section#' + section_id));
        }
    }
};

